class Shop::ExpressTracksController < ShopController
  before_action :set_order

  def index
    @express_tracks = @order.express_tracks.order("created_at DESC").page(params[:page]).per(params[:per])
  end
  
  def show
    @express_track = ExpressTrack.find params[:id]
  end

  def new
    @express_track = ExpressTrack.new
  end

  def create
    @express_track = @order.express_tracks.build express_track_params
    if @express_track.save
      redirect_to shop_order_express_tracks_path(@order), notice: "保存成功！"
    else
      redirect_to shop_order_express_tracks_path(@order), notice: "保存失败！"
    end
  end

  def edit
    @express_track = ExpressTrack.find params[:id]
  end

  def update
    @express_track = ExpressTrack.find params[:id]
    if @express_track.update express_track_params
      redirect_to shop_order_express_tracks_path(@order), notice: "更新成功！"
    else
      redirect_to shop_order_express_tracks_path(@order), notice: "更新失败！"
    end
  end
  
  def destroy
    @express_track = ExpressTrack.find params[:id]
    if @express_track.destroy
      redirect_to shop_order_express_tracks_path(@order), notice: "删除成功."
    else
      redirect_to shop_order_express_tracks_path(@order), notice: "删除失败."
    end
  end

  private

  def set_order
    @order = Order.find params[:order_id]
  end

  def express_track_params
    params.require(:express_track).permit(:content)
  end
end
